/**
 * Author: Andrew Shore
 * Date Last Modified: April 10,2009
 * CSCE 146: Homework 06, Record.java
 * 
 * Description:
 * Basic data payload for the Binary Tree node. Class has
 * constructors, accessors, mutators, a compareTo method,
 * a method to read a record from a file, a toString method,
 * and a method to check if the string element contains only
 * letters.
 */
import java.util.Scanner;


public class Record implements IRecord {
	
	/**
	 * Class variable
	 */
	private String element;

	/**
	 * Default constructor for Record class
	 */
	public Record(){
		
	}
	/**
	 * Constructor for Record class, String parameter sets the value of the Record element
	 */
	public Record(String s){
		element = s;
	}
	
	/**
	 * Accessor for the data element of the Record class
	 */
	public String getElement() {
		return element;
	}
	
	/**
	 * Mutator for the data element of the Record class
	 */
	public void setElement(String what) {
		element = what;
	}
	

	/**
	 * Method compares two Record objects prints out 
	 *                -1 if this record is less than that record
	 * 		           0 if this record is equal to that record
	 * 		 and 	   1 if this record is greater than that record
	 * 
	 * Parameters: that - record being compared
	 */
	public int compareTo(Record that) {
		if(element.toLowerCase().compareTo(that.getElement().toLowerCase()) > 0){
			return 1;
		}
		else if(element.toLowerCase().compareTo(that.getElement().toLowerCase()) < 0){
			return -1;
		}
		else{
			return 0;
		}
		
	}

	

	/**
	 * Determines if the data element contains only letters to ensure that
	 * it is sorted correctly
	 */
	public boolean isAlpha() {
		
		
		//loops through string and checks to see if it is a letter
			for(int i = 0; i < element.length(); i++){
				if(!Character.isLetter(element.charAt(i))){
					return false;
				}
			}
			
		return true;
	}

	/**
	 * Method reads a Record from a input file, the Record is the next String
	 * 
	 * Parameters: inFile - file containing the records
	 */
	public Record readRecord(Scanner inFile) {
		element = inFile.next();
		return this;
	}

	/**
	 * Method returns a string of the data of the Record class
	 */
	public String toString(){
		String s = "";
		s += "	" + element;
		return s;
	}

}
